// src/stores/cityStore.js
import { defineStore } from 'pinia';
import {
    areaCodeGetList
} from '@/api/demand';
const useCityStore = defineStore('city', {
  state: () => ({
    cities: [],
    loading: false,
    error: null,
  }),
  getters: {
    // 可以在这里定义计算属性，例如根据城市列表计算出城市总数
    getCities: (state) => state.cities,
  },
  actions: {
    async fetchCities() {
      this.loading = true;
      this.error = null;

      try {
        const response = await areaCodeGetList(''); // 假设你的 API 端点是 /api/cities
        this.cities = response.data; // 假设返回的数据结构是 { success: true, data: [...] }
      } catch (error) {
        console.log(error)
      } finally {
        this.loading = false;
      }
      
    },
    async initialize() {
        await this.fetchCities();
      },
  },
});
export default  useCityStore